using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
    /// <summary>
    /// Controller class for Allocation
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class AllocationController
    {
        // Preload our schema..
        Allocation thisSchemaLoad = new Allocation();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public AllocationCollection FetchAll()
        {
            AllocationCollection coll = new AllocationCollection();
            Query qry = new Query(Allocation.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public AllocationCollection FetchByID(object AllocationID)
        {
            AllocationCollection coll = new AllocationCollection().Where("AllocationID", AllocationID).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public AllocationCollection FetchByQuery(Query qry)
        {
            AllocationCollection coll = new AllocationCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object AllocationID)
        {
            return (Allocation.Delete(AllocationID) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object AllocationID)
        {
            return (Allocation.Destroy(AllocationID) == 1);
        }
        
        
        
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(string AllocationID,string StoreID)
        {
            Query qry = new Query(Allocation.Schema);
            qry.QueryType = QueryType.Delete;
            qry.AddWhere("AllocationID", AllocationID).AND("StoreID", StoreID);
            qry.Execute();
            return (true);
        }        
       
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string AllocationID,DateTime? AllocationDate,DateTime? ShippedDate,string ShipVia,DateTime? ReceivedDate,string Status,string StoreID,string Principal)
	    {
		    Allocation item = new Allocation();
		    
            item.AllocationID = AllocationID;
            
            item.AllocationDate = AllocationDate;
            
            item.ShippedDate = ShippedDate;
            
            item.ShipVia = ShipVia;
            
            item.ReceivedDate = ReceivedDate;
            
            item.Status = Status;
            
            item.StoreID = StoreID;
            
            item.Principal = Principal;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(string AllocationID,DateTime? AllocationDate,DateTime? ShippedDate,string ShipVia,DateTime? ReceivedDate,string Status,string StoreID,string Principal)
	    {
		    Allocation item = new Allocation();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.AllocationID = AllocationID;
				
			item.AllocationDate = AllocationDate;
				
			item.ShippedDate = ShippedDate;
				
			item.ShipVia = ShipVia;
				
			item.ReceivedDate = ReceivedDate;
				
			item.Status = Status;
				
			item.StoreID = StoreID;
				
			item.Principal = Principal;
				
	        item.Save(UserName);
	    }
    }
}
